package com.kila.aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public class LogAround implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
       //方法体1
        Object result = null;
        try{
            //方法体2
            System.out.println("环绕----前置通知");
            //invocation.proceed()之前的代码：前置通知
            result = invocation.proceed(); //控制着目标方法的执行
            //result 就是目标方法addStudent()的执行返回值
            //invocation.proceed()之后的代码就是后置通知
            System.out.println("环绕----后置通知"+"目标对象："+invocation.getThis()+"--方法名："+invocation.getMethod()+"--方法的参数："+invocation.getArguments().length+"--返回值："+result);

        }catch (Exception e){
            //方法体3
            System.out.println("环绕----异常通知--异常方法"+invocation.getMethod()+"--异常类："+invocation.getThis()+"异常信息"+e.toString());
        }finally {
            System.out.println("环绕----最终通知");
        }


        return result;
    }
}
